// 角色管理数据请求

function manageRole() {

    // 添加新增按钮点击事件
    addBtnAction();

    // 默认加载第一页数据
    pageClickAction();

    function pageClickAction() {
        // console.log(curPage);
        $.ajax({
            url: http_url + 'Role/index',
            type: 'GET',
            data: {
                token: sessionStorage.token,
                page: curPage
            },
            success: function (response) {
                if (response.code == 0) {
                    // $('#ele').find('li').remove();
                    $('tbody').find('tr').remove();
                    showImage(response, pageClickAction);
                }
            }

        });
    }

    function showImage(response, pageClickAction) {

        console.log(response);
        // 创建分页器
        createPagiantion(response, pageClickAction);

        // 展示数据
        var list = response.data.data;
        list.reverse();
        list.forEach(function (data, index) {
            var tr = $('<tr/>').prop('tid', data.id);
            var td_id = $('<td/>').html((curPage - 1) * 10 + index + 1);
            var td_title = $('<td/>').html(data.title);
            var td_permisssions = $('<td/>').html(data.permissions);

            var td_action = $('<td/>').append($('<a/>').prop('href', "#").addClass('delete').html('删除'));
            tr.append(td_id).append(td_title).append(td_permisssions).append(td_action);
            $('#content_wrap table').append(tr);
        });

        // 删除操作的地URL址
        var http_url_delete = http_url + 'Role/delete?token=' + sessionStorage.token + '&id=';
        // 删除操作， 给 class = 'delete' 的 a 标签添加点击事件
        stateDelete($('.delete'), http_url_delete, manageRole);

    }

}
